#include "stdafx.h"
#include <iostream>
#include <string>
#include <new>

using namespace std;
const int BUF=512;

class JustTesting{
private:
	string words;
	int number;
public:
	JustTesting(const string &s="Just Testing",int n=0){
		words = s;
		number = n;
		cout << words <<" constructed\n";
	}
	~JustTesting(){
		cout << words <<" destoryed\n";
	}
	void show()const{
		cout << words <<","<<number<<endl;
	}
};

int main_palcenew1(){
	char *buffer = new char[BUF];
	JustTesting *jt1,*jt2;
	jt1 = new (buffer) JustTesting;
	jt2 = new JustTesting("Heap1",20);

	cout<<"Memory block address:\n" <<"buffer:"
		<<(void *)buffer <<" heap:" <<jt2<<endl;
	cout <<"Memory contents:\n";
	cout <<jt1 << ": ";
	jt1->show();
	cout << jt2<<":";
	jt2 -> show();

	JustTesting *jt3,*jt4;
	jt3 = new (buffer)JustTesting("Bad idea",6);
	jt4 =  new JustTesting("Heap2",10);
	cout <<"Memory contents:\n";
	cout <<jt3 << ": ";
	jt3->show();
	cout << jt4<<":";
	jt4 -> show();

	delete jt2;
	delete jt4;
	delete []buffer;
	cout <<"Done.\n";
	return 0;
}
